package com.web.text.html;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class HtmlItem {
    private final static List<String> TAGS = Arrays.asList("input", "img", "br", "hr", "meta", "link", "base");
    private String content;
    private boolean tag;
    private boolean start;
    private String tagName;
    private List<HtmlItem> children;
    private HtmlItem parent;


    public HtmlItem(String content, boolean tag) {
        this.content = content;
        this.tag = tag;
        if (tag) {
            this.tagName = HtmlStrUtil.getTagName(content);
            this.start = !(content.startsWith("</") || content.endsWith("/>") || TAGS.contains(this.tagName.toLowerCase()));
        }
    }


    public void add(HtmlItem item) {
        if (null == children) {
            children = new ArrayList<>();
        }
        children.add(item);
    }

    public void add(String content, boolean tag) {
        this.add(new HtmlItem(content, tag));
    }


    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public boolean isTag() {
        return tag;
    }

    public void setTag(boolean tag) {
        this.tag = tag;
    }

    public boolean isStart() {
        return start;
    }

    public void setStart(boolean start) {
        this.start = start;
    }

    public String getTagName() {
        return tagName;
    }

    public void setTagName(String tagName) {
        this.tagName = tagName;
    }

    public List<HtmlItem> getChildren() {
        return children;
    }

    public void setChildren(List<HtmlItem> children) {
        this.children = children;
    }

    public HtmlItem getParent() {
        return parent;
    }

    public void setParent(HtmlItem parent) {
        this.parent = parent;
    }
}
